﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using aerthe.Model;
using aerthe.Model.Tasks;

namespace aerthe.Forms
{
    public partial class Form1 : Form
    {
        string BuforString;
        double BuforDouble;

        public Form1()
        {
            InitializeComponent();
        }

        //Task1
        private void task1ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            toolStripProgressBar1.Value = 0;
            listBox1.Items.Clear();
            label1.Text = "Task1";

            MTask1 l1 = new MTask1();

            foreach (var a in l1.ListTask)
            {
                if (this.BuforString == a.Item1)
                {
                    listBox1.Items.Add(new Ciag().Ziag(("----> " + a.Item4)));
                }
                else
                {
                    this.BuforString = a.Item1;
                    listBox1.Items.Add(new Ciag().Ziag((a.Item1 + " - " + a.Item2 + " - " + a.Item3)));
                    listBox1.Items.Add(new Ciag().Ziag(("----> " + a.Item4)));
                }
            }

            toolStripProgressBar1.Value = 100;
        }

        //Task2
        private void task2ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            toolStripProgressBar1.Value = 0;
            listBox1.Items.Clear();
            label1.Text = "Task2";

            MTask2 l2 = new MTask2();

            foreach (var a in l2.ListTask)
            {
                listBox1.Items.Add(new Ciag().Ziag((a.Item1 + " - " + a.Item2)));
            }
                
            toolStripProgressBar1.Value = 100;
        }

        //Task3
        private void task3ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            toolStripProgressBar1.Value = 0;
            listBox1.Items.Clear();
            label1.Text = "Task3";

            MTask3 l3 = new MTask3();

            foreach (var a in l3.ListTask)
            {
                listBox1.Items.Add(new Ciag().Ziag((a.Item1 + " - " + a.Item2)));
            }

            toolStripProgressBar1.Value = 100;
        }
        
        //Task4
        private void task4ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            toolStripProgressBar1.Value = 0;
            listBox1.Items.Clear();
            label1.Text = "Task4";

            MTask4 l4 = new MTask4();

            foreach (var a in l4.ListTask)
            {
                if (this.BuforString == a.Item1)
                {
                    listBox1.Items.Add(new Ciag().Ziag(("----> " + a.Item2)));
                }
                else
                {
                    this.BuforString = a.Item1;

                    listBox1.Items.Add(new Ciag().Ziag((a.Item1)));
                    listBox1.Items.Add(new Ciag().Ziag(("----> " + a.Item2)));
                }
            }

            toolStripProgressBar1.Value = 100;
        }

        //Task5
        private void task5ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            toolStripProgressBar1.Value = 0;
            listBox1.Items.Clear();
            label1.Text = "Task5";

            MTask5 l5 = new MTask5();

            foreach (var a in l5.ListTask)
            {
                BuforDouble = Convert.ToDouble(a.Item2);

                if (BuforDouble > 100000)
                {
                    if (BuforString != "Gold")
                    {
                        BuforString = "Gold";
                        listBox1.Items.Add(new Ciag().Ziag(BuforString));
                    }
                }
                else if (BuforDouble > 10000)
                {
                    if (BuforString != "Silver")
                    {
                        BuforString = "Silver";
                        listBox1.Items.Add(new Ciag().Ziag(BuforString));
                    }
                }
                else
                {
                    if (BuforString != "Normal")
                    {
                        BuforString = "Normal";
                        listBox1.Items.Add(new Ciag().Ziag(BuforString));
                    }
                }

                listBox1.Items.Add(new Ciag().Ziag(("----> " + a.Item1 + " - " + a.Item2)));
            }

            toolStripProgressBar1.Value = 100;
        }

        //Exit
        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
    }
    public class Ciag
    {
        public String ciag;
        public Ciag() { }
        public String Ziag(String ciag) { this.ciag = ciag; return ciag; }
    }
}
